/**
 * 
 */
package com.orange.modules.dao.manage;

import java.sql.SQLException;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.orange.dbhelp.DbHelper;
import com.orange.dbhelp.page.Page;
import com.orange.modules.entity.manage.AuthAnnouncement;
import com.orange.modules.entity.manage.AuthSysDownload;

/**
 * @author gaogs
 *
 * 2016-12-15
 */
@Repository
public class AuthAnnouncementRepository {
	
	@Resource(name = "dbHelper")
	private DbHelper dbHelper;
	
	@Autowired
	private AuthAnnouncementDao authAnnouncementDao;
	
	/**
	 * 保存公告信息
	 * @param a
	 */
	public void saveAuthAnnouncementInfo(AuthAnnouncement a){
		authAnnouncementDao.save(a);
	}
	
	/**
	 * 根据id查询公告信息
	 * @param pid
	 * @return
	 */
	public AuthAnnouncement queryAuthAnnouncementById(String pid){
		AuthAnnouncement a=authAnnouncementDao.findOne(pid);
		return a;
	}
	
	/**
	 * 根据公告id删除公告信息
	 * @param pid
	 */
	public void deleteAuthAnnouncementInfo(String pid){
		authAnnouncementDao.delete(pid);
	}
	
	/**
	 * 
	 * @param map
	 * @return
	 * @throws SQLException
	 */
	public Page<AuthAnnouncement> queryAuthSysDownloadInfoPage(Map<String,String>map) throws SQLException{
		StringBuilder sql = new StringBuilder("SELECT TOP 1000 a.p_id as pid ,a.s_title as title ," +
				" a.s_content as content ," +
				" a.s_type as type ,a.s_create_time as createTime " +
				" FROM t_auth_announcement as a WHERE 1=1 " );
		if(StringUtils.isNotBlank(map.get("title"))){
			sql.append(" AND a.s_title like '%"+map.get("title")+"%'");
		}
		if(StringUtils.isNotBlank(map.get("type"))){
			sql.append(" AND a.s_type ='"+map.get("type")+"'");
		}
		sql.append(" ORDER BY a.s_create_time DESC ");
		Page<AuthAnnouncement> authAnnouncements = dbHelper.getPage(sql.toString(), AuthAnnouncement.class,Integer.valueOf(map.get("pageNumber")), Integer.valueOf(map.get("pageSize")),new Object[] {});
		return authAnnouncements;
	}
	

}
